<?php
class model_newagk_examsession extends gdl_components_basemodel
{

    public function primarykey() {
        return 'id';
    }

    public function tableName() {
        return 'agk_examsession';
    }
	public function getExamSessionBySessionid($basicid,$identity_id,$sign=1){
		return $this->getListByArgOne('basicid='.$basicid.' and identity_id='.$identity_id.' and sign='.$sign);
	}
	
	public function getListByArgOne($condition,$field='*')
    {
        return $this->selectOne($condition,$field);
    }
	public function addExamHistory($identity_id, $list,$basicid){
		$sign = $basicid ? 1 : 2;
		$sessionval = $this->getListByArgOne(['identity_id'=>$identity_id,'sign'=>$sign],'papername,starttime');//,'basicid'=>$basicid 完全没必要了这个参数
		if(!empty($sessionval['starttime'])){
			$this->delete(['identity_id'=>$identity_id,'sign'=>$sign]);
		}
		$usercompany = new model_newagk_usercompany();
		$ucentermember = new model_uc_ucentermember();
		$gdlUserId = $usercompany->getInfoArgOne(['id'=>$identity_id],'gdlUserId');
		$truename = $ucentermember->selectOne(['id'=>$gdlUserId['gdlUserId']],'truename');
		
		
		
		$setting = ['qbankName'=>$list['qbankName'],'qbankId'=>$list['qbankId'],'duration'=>$list['duration'],'totalScore'=>$list['totalScore'],'passScore'=>$list['passScore'],'paperName'=>$list['paperName'],'setting'=>$list['setting']];
		$data['es_id'] = md5($identity_id);
		$data['identity_id'] = $identity_id;// '身份ID',
		$data['name'] = empty($truename['truename']) ? '' : $truename['truename'];// '用户名',
		$data['setting'] = serialize($setting);// '配置',
		$data['starttime'] = time();// '开始时间',
		$data['sign'] = $sign;// '1是正式考试2是模拟考试',
		$data['basicid'] = $basicid;// '考场',
		$data['type'] = 2;// '类型'没发现有什么用处,
		$data['paperid'] = $list['id'];// '试卷id',
		$data['papername'] = $list['paperName'];// '试卷名',
		$data['question'] = serialize($list['list']);// '题目',
		$data['time'] = $list['duration'];// '总时长',
		$sessionid = $this->insert($data);
		
		return $sessionid;
		
	}
	 
}
